package boot.spring.mapper;

import boot.spring.po.Actor;
import boot.spring.po.Post;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

//mybatis的实体类和hibernate实体类的不同是mybatis的实体类不需要加载到spring的beanFactory中，
//而是通过操作数据库的mapper来持久化数据,相当于DAO层。
import org.apache.ibatis.annotations.Param;

public interface PostMapper {
	@Select("select * from post")
	public List<Post> gelallpost();

	@Insert("insert into post (title, content, category) " +
			"values (#{title}, #{content}, #{category})")
	void insertPost(Post post);

	@Delete("delete from post where id = #{postId}")
	void deletePost(int postId);

    @Select("SELECT * FROM post LIMIT #{offset}, #{pageSize}")
    List<Post> getPostsByPage(@Param("offset") long offset, @Param("pageSize") int pageSize);

    @Select("SELECT COUNT(*) FROM post")
    long getTotalCount();

	@Select("select * from post where id = #{postId}")
	Post getPostById(int postId);
}
